home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 606 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.1 KB

  1. Path: chronicle.mti.sgi.com!austern
  2. From: boukanov@afrodite.fi.uib.no (Igor Boukanov)
  3. Newsgroups: comp.std.c++
  4. Subject: constant-expression extension
  5. Date: 01 Mar 1996 09:03:14 PST
  6. Organization: Fysisk institutt, Universitetet i Bergen
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <4h775a$m4s@ugress.uib.no>
  9. NNTP-Posting-Host: isolde.mti.sgi.com
  10. Summary: Such extension can reduce number of macros in programs.
  11. Keywords: constant-expression, macro
  12. X-Original-Date: 1 Mar 1996 16:03:54 GMT
  13. X-Newsreader: TIN [version 1.2 PL2]
  14. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  15.     iQBVAwUBMTcuBUy4NqrwXLNJAQFrLgH+NUBP2rhqYFPDLgzenmMNUlZqKPi2OGEj
  16.     74hZvZpMqyKChCgLzNHDTejDeNjimPQ6ugMHdtweKUsRJcxTwA9TYg==
  17.     =fLS8
  18. Originator: austern@isolde.mti.sgi.com
  19.  
  20.    My proposal is to change definition of the 
  21. "integral constant-expression"[5.19] to something like this:
  22.  
  23. An    integral   constant-expression is an expression that can be calculated
  24. at the compilation phase. 
  25.  
  26. And according to this one would be able to use inline
  27. functions in constant-expressions and instead of writing:
  28.  
  29. #define ALIGN(number, base) ((number + base - 1) / base * base)
  30. #define MAX(x, y) ((x > y) ? (x) : (y))
  31. #define GRAD_TO_RADIAN(x) (x * 3.1415926 / 180)
  32.  
  33.    char buf[ALIGN(50, sizeof(float))];
  34.    char buf2[MAX(sizeof(long), sizeof(double))];
  35.    const double angle = GRAD_TO_RADIAN(30);
  36.    
  37.  
  38. one can write:
  39.  
  40. inline unsigned T align(unsigned number, unsigned base) {
  41.    return ((number + base - 1) / base * base);
  42.  
  43. template<class T> inline T max(T x, T y){ 
  44.    return (x > y) ? x : y;
  45.  
  46. inline double grad_to_radian(double x){
  47.    return x * 3.1415926 / 180;
  48. }
  49.  
  50.    char buf[align(50, sizeof(float))];
  51.    char buf2[max(sizeof(long), sizeof(double))];
  52.    const double angle = grad_to_radian(30);
  53.  
  54. So what do you think about this?
  55.  
  56. --
  57. Regards, 
  58. Igor Boukanov (igor.boukanov@fi.uib.no).
  59. ---
  60. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
  61.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  62.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  63.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  64.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  65. ]
  66.